package com.chinact.saas.tenant.orggroup.dao.impl;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import com.chinact.platform.util.exception.SystemErrorExcetion;
import com.chinact.platform.util.log.Log;
import com.chinact.saas.tenant.orggroup.dao.IOrgGroupDao;
import com.chinact.saas.tenant.orggroup.domain.OrgGroupObj;

/**
 * Title: ChinaCT SaaS
 * <p>
 * Description: 组织组织归口（单位归口）管理
 * <p>
 * Copyright: 2008
 * <p>
 * Company: Liaoning Open Data Communication Co.,Ltd.
 *
 * @author lihui
 * @version 1.0.0
 */
//@DynamicRoutingDataSource()
@Repository(value = "upOrgGroupDao")
public class OrgGroupDaoImpl extends JdbcDaoSupport implements IOrgGroupDao {
	@Autowired(required = false)
	protected DataSource ctSaaSIDSDataSource;

	@PostConstruct
	private void initialize() {
		setDataSource(ctSaaSIDSDataSource);
	}

	/**
	 * 保存对象
	 *
	 * @param obj
	 *            对象
	 * @throws SystemErrorExcetion
	 *             系统异常
	 */
	@Override
	public void save(final OrgGroupObj obj) throws SystemErrorExcetion {
		final StringBuffer sql = new StringBuffer("INSERT INTO " + OrgGroupObj.TABLE_NAME + " (" + OrgGroupObj.TABLE_ID
				+ ", ORGGROUP_LOGIC_ID, ORGGROUP_NAME, ORGGROUP_ORDER, ORGGROUP_MEMO, ORGAN_IDS, ORGAN_NAMES,"
				+ " CREATE_TIME, CREATE_PERSON, UPDATE_TIME, UPDATE_PERSON,"
				+ " EXT1, EXT2, EXT3) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

		Log.info(sql.toString());

		getJdbcTemplate().update(sql.toString(),
				new Object[] { obj.getId(), obj.getLogicId(), obj.getOrgGroupName(), obj.getOrgGroupOrder(),
						obj.getOrgGroupMemo(), obj.getOrganIds(), obj.getOrganName(), obj.getCreateTime(),
						obj.getCreatePerson(), obj.getUpdateTime(), obj.getUpdatePerson(), obj.getExt1(), obj.getExt2(),
						obj.getExt3() });
	}

}
